<?
	include_once("codelibrary/inc/variables.php");//Using variables.php for Database Connectivity
	include_once("codelibrary/inc/functions.php");//Using functions.php for using getAnyTableWhereData()
	$row_file=getAnyTableWhereData($backfilling_details_table," and BackfillingID='$id'");
	$last_insert_id=$id;
	if($Backfilling_Date!="")
	{
	   $BackfillingDate=$Backfilling_Date;
	}
	
	
	//------------------------------- Weld Joint From ---------------------------------
	$TN_WeldJointNo_From =$TN_WeldJointNo_From;
	$JointText = preg_replace('/\s+/', '',$TN_WeldJointNo_From);
	$JointFrom = strtoupper($JointText);
		  
	
	
	//------------------------------- Weld Joint To ---------------------------------
	$TN_WeldJointNo_To =$TN_WeldJointNo_To;
	$JointText = preg_replace('/\s+/', '',$TN_WeldJointNo_To);
	$JointTo = strtoupper($JointText);						
	            
	

	if(empty($JointFrom) && empty($JointTo))
	{
		$ChainageFrom=$TN_Chainage_From;
		$ChainageTo=$TN_Chainage_To;
	}
	else
	{
		 	list($ChFrom,$Ch_SeqFrom,$SeqFrom,$SubSeqFrom,$SubSeq_SeqFrom)=getWeldDetails($JointFrom);
			list($ChTo,$Ch_SeqTo,$SeqTo,$SubSeqTo,$SubSeq_SeqTo)=getWeldDetails($JointTo);
	      
		    $ChFrom=$ChFrom;
			$Ch_SeqFrom = $Ch_SeqFrom;
			$SeqFrom = $SeqFrom;
            $SubSeqFrom =$SubSeqFrom;
			$SubSeq_SeqFrom= $SubSeq_SeqFrom;
			
			$ChTo=$ChTo;
			$Ch_SeqTo=$Ch_SeqTo;
			$SeqTo=$SeqTo;
			$SubSeqTo=$SubSeqTo;
			$SubSeq_SeqTo=$SubSeq_SeqTo;
	}
	
	$BackfillingReptNo=$TR_Report_Number;
	$CrossingID=$TR_Crossing;
	$Remarks=$TN_Remarks;
	$PipeTopLevel=$MN_PipeTopLevel;
	$NaturalGroundLevel=$MN_NaturalGroundLevel;
    
	editData($backfilling_details_table,"BackfillingID",$id);
    
	if($Scanned_Document_name!="")
	{	
		$path_unlink=$backfilling_folder.$BackfillingReptNo."_"."Backfilling"."_".$row_file["ScannedForm"];
		if(file_exists($path_unlink))
		{
			unlink($path_unlink);
		}
		$qry_delete="update $backfilling_details_table set ScannedForm=' ' where BackfillingReptNo='$BackfillingReptNo'";
		mysql_query($qry_delete);
		if($special!='' && $special=='Open')
		{
			$file_name=$BackfillingReptNo."_"."OpenCutBackfilling"."_".$Scanned_Document_name;
			$destination=$OpenCutBackfilling_Folder.$file_name;
		}
		else
		{
			$file_name=$BackfillingReptNo."_"."Backfilling"."_".$Scanned_Document_name;
			$destination=$backfilling_folder.$file_name;
		}
		upload_my_file($Scanned_Document,$destination);
		//storing image name in database
		$ScannedForm=$Scanned_Document_name;
		//editData($backfilling_details_table,"BackfillingReptNo",$BackfillingReptNo);
		mysql_query("Update $backfilling_details_table Set ScannedForm='$Scanned_Document_name' where BackfillingReptNo='$BackfillingReptNo'");

	}
	if($special!='')
	{
		switch($special)
		{
			case 'Open':
						header("location: OpenCut-Backfilling-View-Details.php?msg=Edited");
						break;
			case 'HDD':
						header("location: HDD-Backfilling-View-Details.php?msg=Edited");
						break;
			default:
						header("location: Backfilling-View-Details.php?msg=Edited");
						break;
		}
	}
	else
	{
		header("location: Backfilling-View-Details.php?msg=Edited");
	}
	die();
?>